home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / Scripting / Source / StevesFlowControl.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-09-09  |  2.7 KB  |  77 lines  |  [TEXT/MPCC]

  1. /*---------------------------------------------------------------
  2.     Copyright 1995, Steve Israelson
  3.     
  4.     I own this code.  You are free to use this code in any software
  5.     you want.  You may not sell this source code at all, you can 
  6.     sell your product though.  If you want to include this code
  7.     in any code collection (CD-Roms etc) this is OK as long as
  8.     I get a complimentary copy.
  9.             Steve.
  10.     
  11.     Holds a list of regular expression and matches them to an input
  12.     string.  Automatically handles all flow control constructs,
  13.     like if-then, while etc.
  14.     If it returns kToken_Unknown, then this token must be parsed
  15.     by the caller.
  16.     
  17.     To evaluate if() statements and other conditional statements
  18.     the parser needs to evaluate numerical expressions.  To do
  19.     this, it HAS to call your code, since you are the only one
  20.     that can evaluate variables etc.  To do this, you pass in
  21.     the function that evaluates numerical expressions and it
  22.     will get called when it needs to be.
  23. ---------------------------------------------------------------*/
  24. #pragma once
  25. #include "StevesParser.h"
  26. #include "FlowTokens.h"
  27.  
  28.  
  29. // used for subroutines
  30. typedef struct {
  31.     long        itsLineNum;            // the line number where this subroutine starts
  32.     char        itsName[64];        // the name of this subroutine, 64 chars max
  33.     } subroutineEntry;
  34.  
  35. // used for our stack
  36. typedef struct {
  37.     long        token;                // the token we represent
  38.     long        itsLineNum;            // the line we found this token on
  39.     char        *theLabel;            // the label we are searching for, for gosub calls only
  40.     Boolean        isExecuting;        // are we executing code?
  41.     Boolean        isSearching;        // are we searching?
  42.     Boolean        conditionState;        // for conditional execution
  43.     } stackEntry;
  44.  
  45.  
  46. // This type of function will get called to evaluate a numerical expression
  47. // Implement it and pass it into the constructor.
  48. typedef long (*numericalExpParser)(char *text, long userData);
  49.  
  50.  
  51. class MyFlowControl
  52.     {
  53. public:
  54.                         MyFlowControl(numericalExpParser theNumEvaluator, long itsData);
  55.                         ~MyFlowControl();
  56.     long                Parse(char *text, long *theLineNum);
  57.  
  58. private: 
  59.     LList                Stack;                // stack, for nesting ifs etc
  60.     LList                Subroutines;        // list of subroutines and their line nums
  61.     MyParser            theParser;            // For Control statements
  62.     MyParser             expressions;        // For if statements, etc
  63.     numericalExpParser    evalNumber;            // pointer to users number evaluater
  64.     long                theUserData;        // the users data
  65.     
  66.     void                BuildFlowControlParser(void);
  67.     void                BuildExpressionParser(void);
  68.     subroutineEntry     *FindSubroutine(char *text);
  69.     void                AddLongParam(LList *theParams, long theNum);
  70.     void                PushOntoStack(long token, long theLineNum, char *theLabel, 
  71.                                             Boolean conditionState, Boolean canExecute, 
  72.                                             Boolean isSearching);
  73.     void                PopStack(void);
  74.     Boolean                EvalExpression(char *theExpression);
  75.     };                     
  76.  
  77.